package com.zx.ishopping.controller.admin;

import com.zx.ishopping.DTO.OrderDTO;
import com.zx.ishopping.DTO.OrderPageDTO;
import com.zx.ishopping.entity.OrderStatusCount;
import com.zx.ishopping.results.PageResult;
import com.zx.ishopping.results.Result;
import com.zx.ishopping.services.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单管理模块
 */

@RestController
@RequestMapping("/admin/order")
@Slf4j
public class orderController {

    @Autowired
    private OrderService orderService;
    /**
     * 订单查询分页查询
     * 
     */
    @GetMapping("/pageQuery")
    public Result<PageResult> pageQuery(OrderPageDTO orderPageQueryDTO){
        log.info("订单查询分页查询{}",orderPageQueryDTO);
        PageResult pageResult =  orderService.pageQuery(orderPageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 根据id删除订单
     * @param id
     * @return
     */
    @DeleteMapping("/deleteOrder")
    public Result deleteOrder (Long id){
        orderService.deleteOrder(id);
        return Result.success();
    }


    /**
     * 更新订单信息
     * @param orderDTO
     * @return
     */
    @PutMapping("/updateOrder")
    public Result updateOrder(@RequestBody OrderDTO orderDTO){
        log.info("更新的订单信息{}",orderDTO);
        orderService.updateOrder(orderDTO);
        return Result.success();
    }

    /**
     * 更新订单状态
     * @param status 订单状态
     * @param id 订单id             
     *
     */
        @PutMapping("/updateOrderStatus/{id}")
        public Result updateOrderStatus(@RequestParam Integer status,@PathVariable Long id){
            
            orderService.updateOrderStatus(status,id);
            return Result.success();
        }

    /**
     * 获取各个状态的订单数量
     * @return
     */
    @GetMapping("/getOrderCountByStatus")
        public Result<List<OrderStatusCount>> getOrderCountByStatus(){
        List<OrderStatusCount> orderStatusCounts = orderService.getOrderCountByStatus();
            return Result.success(orderStatusCounts);
        }
}
